<table class="table table-striped table-bordered bootstrap-datatable datatable " id="table_customer_order">
    <thead>

    <tr >
        <th>STT</th>
        <th>Tên FB</th>
        <th>Phone</th>
        <th>Mã SP</th>

        <th>Size</th>
        <th>Số Lượng</th>
        <th>Màu</th>
        <th>Ảnh</th>
        <th>Order status</th>
        <th>Ghi chú sản phẩm</th>
        <th class="gp_3">Giá<br/>(x1000 VNĐ)</th>
        <th class="gp_2">Giá AT<br/>(EU)</th>
        <th class="gp_1">Giá PT<br/>(EU)</th>
        <th class="gp_2">Tổng AT<br/>(EU)</th>
        <th class="gp_1">Tổng PT<br/>(EU)</th>

        <th class="gp_3">Tổng Tiền<br/>(x1000 VNĐ)</th>
        <th class="gp_3">Tổng Cọc<br/>(x1000 VNĐ)</th>
        <th class="gp_3">Thiếu<br/>(x1000 VNĐ)</th>
        <th class="gp_3">Thừa<br/>(x1000 VNĐ)</th>
        <th class="">Ghi chú đơn hàng</th>
        <th class="gp_4">Địa chỉ</th>
        <th class="gp_4">Tỉnh</th>
        <th class="gp_4">Tên thật</th>
        <th class="gp_4">Tài khoản bank</th>
        <th>Actions</th>
    </tr>
    </thead>
    <tbody id="tbody_order_list">
    <?php
    if ($list_customer_order) {
        $customer_order_id = 0;
        $count = 0;

        foreach ($list_customer_order as $customer_order) {
            $random_code = $customer_order->code_view;

            $color_photo_name = $customer_order->product_color . "_" . $customer_order->product_code . "_" . $customer_order->manufacture;
            $color_photo_name = $core->convert_string_friendly($color_photo_name) . ".jpg";
            $path_color_photo = dirname(dirname(__FILE__)) . DS . "photo" . DS . "extra_photo" . DS . "thumb_extra_photo" . DS . $color_photo_name;

            if (file_exists($path_color_photo)) {
                $src_photo = 'photo/extra_photo/' . $color_photo_name;
                $src_photo_thumb = 'photo/extra_photo/thumb_extra_photo/' . $color_photo_name;
            } else {
                $src_photo = 'photo/' . $customer_order->main_photo;
                $src_photo_thumb = 'photo/thumb_photo/200_' . $customer_order->main_photo;
            }
            if ($customer_order_id != $customer_order->customer_order_id) {

                $count++;
                $customer_order_id = $customer_order->customer_order_id;
                ?>
                <tr class="tr_<?php echo $customer_order->customer_order_id; ?>">
                    <td class="center" rowspan="<?php echo $customer_order->total_product; ?>"><?php echo $count; ?></td>
                    <td class="center" rowspan="<?php echo $customer_order->total_product; ?>">
                        <?php
                        if ($customer_order->facebook_link != "") {
                            ?>
                            <a href="<?php echo $customer_order->facebook_link; ?>"
                               target="_blank"><?php echo $customer_order->facebook_name; ?></a>
                        <?php
                        } else {
                            echo $customer_order->facebook_name;
                        }
                        ?>
                        <p></p>
                        <select class='select_customer_order_status'
                                id="select_customer_order_status_<?php echo $customer_order->customer_order_id; ?>"
                                style="width: 120px;margin-top:10px"
                                rel="<?php echo $customer_order->customer_order_id; ?>">
                            <option value=0 <?php if ($customer_order->customer_order_status == 0) echo 'selected'; ?>>
                                Store
                            </option>
                            <option value=1 <?php if ($customer_order->customer_order_status == 1) echo 'selected'; ?>>
                                Online
                            </option>
                            <option value=2 <?php if ($customer_order->customer_order_status == 2) echo 'selected'; ?>>Hàng
                                có sẵn
                            </option>
                            <option value=3 <?php if ($customer_order->customer_order_status == 3) echo 'selected'; ?>>Đã
                                nhận hàng
                            </option>
                            <option value=4 <?php if ($customer_order->customer_order_status == 4) echo 'selected'; ?>>Đang
                                shipping
                            </option>
                            <option value=5 <?php if ($customer_order->customer_order_status == 5) echo 'selected'; ?>>Khách
                                đã nhận
                            </option>
                            <option value=6 <?php if ($customer_order->customer_order_status == 6) echo 'selected'; ?>>Hết
                                hàng
                            </option>
                            <option value=7 <?php if ($customer_order->customer_order_status == 7) echo 'selected'; ?>>
                                ORDER
                            </option>
                            <option value=8 <?php if ($customer_order->customer_order_status == 8) echo 'selected'; ?>>Chưa
                                chắc chắn
                            </option>
                            <option value=9 <?php if ($customer_order->customer_order_status == 9) echo 'selected'; ?>>Chưa
                                xác định
                            </option>
                        </select>

                        <p></p>
                        <button class="btn btn-primary print_address_customer" type="button"
                                rel='<?php echo $customer_order->customer_id; ?>'>Print address
                        </button>
                        <p></p>
                        <a target="_blank"
                           href="../customerOrder.php<?php echo '?id=' . $customer_order->customer_order_id . '&code=' . $random_code; ?>">Link
                            đơn hàng</a>
                        <p></p>
                        <?php
                        if($customer_order->type_calculate_payment !='normal'){
                            echo "<b>Khách buôn (".strtoupper($customer_order->type_calculate_payment).")</b>";
                        }
                        ?>
                    </td>
                    <td class="center" rowspan="<?php echo $customer_order->total_product; ?>">
                        <a href="addCustomer.php?id=<?php echo $customer_order->customer_id; ?>"
                           target="_blank"><?php echo $customer_order->phone; ?></a>

                    </td>
                    <?php
                    if ($customer_order->link_web == "") {
                        ?>
                        <td class="center color_status"><?php echo $customer_order->product_code; ?></td>
                    <?php
                    } else {
                        ?>
                        <td class="center color_status"><a href="<?php echo $customer_order->link_web; ?>"
                                                           target="_blank"><?php echo $customer_order->product_code; ?></a>
                        </td>
                    <?php
                    }
                    ?>


                    <td class="center color_status"><?php echo $customer_order->product_size; ?></td>
                    <td class="center color_status">
                        Khách đặt: <?php echo $customer_order->order_product_num; ?>
                        <p>
                            Đã mua: <span id="show_item_product_num_<?php echo $customer_order->id; ?>"><?php echo $customer_order->product_num; ?></span>
                        <div class="input-append">

                            <input style="width: 50px;display: none" type="text" id="mrk_bought_product_num_<?php echo $customer_order->id; ?>" name="customer_phone" size="5" value="<?php echo $customer_order->product_num; ?>" >
                            <button class="mrk_edit_product_num btn"  type="button" data-item-id="<?php echo $customer_order->id; ?>">Sửa</button>
                            <button class="mrk_update_product_num btn" style="display: none" type="button" data-item-id="<?php echo $customer_order->id; ?>">Lưu</button>
                        </div>
                        </p>

                    </td>
                    <td class="center color_status"><?php echo $customer_order->product_color; ?></td>

                    <td class="center color_status"><img rel="<?php echo $src_photo; ?>" class="photo_product"
                                                         src="<?php echo $src_photo_thumb; ?>" width="100px"></td>
                    <td class="center color_status">
                        <select
                            class='select_order_status common_order_status_<?php echo $customer_order->customer_order_id; ?>'
                            style="width: 120px;" rel="<?php echo $customer_order->id; ?>">
                            <option value=0 <?php if ($customer_order->order_status == 0) echo 'selected'; ?>>Store</option>
                            <option value=1 <?php if ($customer_order->order_status == 1) echo 'selected'; ?>>Online
                            </option>
                            <option value=2 <?php if ($customer_order->order_status == 2) echo 'selected'; ?>>Hàng có sẵn
                            </option>
                            <option value=3 <?php if ($customer_order->order_status == 3) echo 'selected'; ?>>Đã nhận hàng
                            </option>
                            <option value=4 <?php if ($customer_order->order_status == 4) echo 'selected'; ?>>Đang
                                shipping
                            </option>
                            <option value=5 <?php if ($customer_order->order_status == 5) echo 'selected'; ?>>Khách đã
                                nhận
                            </option>
                            <option value=6 <?php if ($customer_order->order_status == 6) echo 'selected'; ?>>Hết hàng
                            </option>
                            <option value=7 <?php if ($customer_order->order_status == 7) echo 'selected'; ?>>ORDER</option>
                            <option value=8 <?php if ($customer_order->order_status == 8) echo 'selected'; ?>>Chưa chắc
                                chắn
                            </option>
                        </select>
                        <?php
                        if ($customer_order->order_status == 0) {
                            echo '<div>' . $core->changeDateMysqlToShow($customer_order->store_date) . '</div>';
                        } elseif ($customer_order->order_status == 1) {
                            echo '<div>' . $core->changeDateMysqlToShow($customer_order->online_date) . '</div>';
                        } elseif ($customer_order->order_status == 3) {
                            echo '<div>' . $core->changeDateMysqlToShow($customer_order->received_date) . '</div>';
                        } elseif ($customer_order->order_status == 5) {
                            echo '<div>' . $core->changeDateMysqlToShow($customer_order->saled_date) . '</div>';
                        } elseif ($customer_order->order_status == 7) {
                            echo '<div>' . $core->changeDateMysqlToShow($customer_order->customer_order_date) . '</div>';
                        }
                        ?>
                        <div class="history_status"></div>
                    </td>
                    <td class="center color_status">
                        <p class="description_product_detail" data-item-id="<?php echo $customer_order->id; ?>"><?php echo nl2br(htmlspecialchars($customer_order->description)); ?></p>
                        <button class="popup_edit_note_product" class="btn" type="button" rel="<?php echo $customer_order->id; ?>">Sửa</button>

                    </td>
                    <td class="center gp_3"
                        id="td_price_<?php echo $customer_order->id; ?>">
                        <?php
                        if ($customer_order->order_status == 6) {
                            echo '0';
                        }
                        else {
                            echo number_format($customer_order->product_price / 1000);


                        }
                        ?>
                    </td>
                    <td class="center gp_2"
                        id="td_stamp_price_<?php echo $customer_order->id; ?>"><?php if ($customer_order->order_status == 6) echo '0'; else echo number_format($customer_order->stamp_price, 2); ?></td>
                    <td class="center gp_1"
                        id="td_store_price_<?php echo $customer_order->id; ?>"><?php if ($customer_order->order_status == 6) echo '0'; else echo number_format($customer_order->store_price, 2); ?></td>
                    <td class="center gp_2" id="td_total_stamp_price_<?php echo $customer_order->customer_order_id; ?>"
                        rowspan="<?php echo $customer_order->total_product; ?>"><?php echo number_format($customer_order->total_at); ?></td>
                    <td class="center gp_1" id="td_total_store_price_<?php echo $customer_order->customer_order_id; ?>"
                        rowspan="<?php echo $customer_order->total_product; ?>"><?php echo number_format($customer_order->total_pt); ?></td>


                    <td class="center gp_3" id="td_total_price_<?php echo $customer_order->customer_order_id; ?>"
                        rowspan="<?php echo $customer_order->total_product; ?>"><?php echo number_format($customer_order->total_order_money / 1000,2,',','.'); ?></td>
                    <td class="center gp_3" rowspan="<?php echo $customer_order->total_product; ?>">

                        <a class="popup_zen_payment" id="href_payment_<?php echo $customer_order->customer_order_id; ?>"
                           href="javascript:void(0);"
                           rel="<?php echo $customer_order->customer_order_id; ?>"><?php echo number_format($customer_order->total_payment / 1000); ?></a>
                    </td>
                    <td class="center gp_3" id="td_debit_<?php echo $customer_order->customer_order_id; ?>"
                        rowspan="<?php echo $customer_order->total_product; ?>"><?php
                        if ($customer_order->total_current_money < 0)
                            echo number_format($customer_order->total_current_money / 1000);
                        else
                            echo "0";
                        ?></td>
                    <td class="center gp_3" id="td_excess_cash_<?php echo $customer_order->customer_order_id; ?>"
                        rowspan="<?php echo $customer_order->total_product; ?>">
                        <?php
                        if ($customer_order->total_current_money > 0)
                            echo number_format($customer_order->total_current_money / 1000);
                        else
                            echo "0";
                        ?>
                    </td>
                    <td class="center"
                        rowspan="<?php echo $customer_order->total_product; ?>"><?php echo $customer_order->order_description; ?></td>
                    <td class="center gp_4"
                        rowspan="<?php echo $customer_order->total_product; ?>"><?php echo $customer_order->address; ?></td>
                    <td class="center gp_4" rowspan="<?php echo $customer_order->total_product; ?>">
                        <?php
                        if ($customer_order->province == 1)
                            echo "Ở tỉnh";
                        else
                            echo "Ở HN";
                        ?>
                    </td>
                    <td class="center gp_4"
                        rowspan="<?php echo $customer_order->total_product; ?>"><?php echo $customer_order->name; ?></td>
                    <td class="center gp_4"
                        rowspan="<?php echo $customer_order->total_product; ?>"><?php echo $customer_order->bank_account; ?></td>
                    <td class="center " rowspan="<?php echo $customer_order->total_product; ?>">
                        <a class="btn btn-info btn_edit_customer_order" href="javascript:void(0)"
                           rel="<?php echo $customer_order->customer_order_id; ?>">
                            <i class="icon-edit icon-white"></i>
                            Edit
                        </a>
                        <a style=" margin: 10px 0px;" rel="<?php echo $customer_order->customer_order_id; ?>"
                           class="btn btn-danger btn_delete_order_detail" href="javascript:void(0)">
                            <i class="icon-trash icon-white"></i>
                            Delete
                        </a>
                    </td>
                </tr>
            <?php
            } else {
                ?>
                <tr class="tr_<?php echo $customer_order->customer_order_id; ?>">
                    <?php
                    if ($customer_order->link_web == "") {
                        ?>
                        <td class="center color_status"><?php echo $customer_order->product_code; ?></td>
                    <?php
                    } else {
                        ?>
                        <td class="center color_status"><a href="<?php echo $customer_order->link_web; ?>"
                                                           target="_blank"><?php echo $customer_order->product_code; ?></a>
                        </td>
                    <?php
                    }
                    ?>

                    <td class="center color_status"><?php echo $customer_order->product_size; ?></td>
                    <td class="center color_status">
                        Khách đặt: <?php echo $customer_order->product_num; ?>
                        <p>
                            Đã mua: <span id="show_item_product_num_<?php echo $customer_order->id; ?>"><?php echo $customer_order->product_num; ?></span>
                        <div class="input-append">

                            <input style="width: 50px;display: none" type="text" id="mrk_bought_product_num_<?php echo $customer_order->id; ?>" name="customer_phone" size="5" value="<?php echo $customer_order->product_num; ?>" >
                            <button class="mrk_edit_product_num btn"  type="button" data-item-id="<?php echo $customer_order->id; ?>">Sửa</button>
                            <button class="mrk_update_product_num btn" style="display: none" type="button" data-item-id="<?php echo $customer_order->id; ?>">Lưu</button>
                        </div>
                        </p>

                    </td>
                    <td class="center color_status"><?php echo $customer_order->product_color; ?></td>
                    <td class="center color_status"><img rel="<?php echo $src_photo; ?>" class="photo_product"
                                                         src="<?php echo $src_photo_thumb; ?>" width="100px"></td>
                    <td class="center color_status">
                        <select
                            class='select_order_status common_order_status_<?php echo $customer_order->customer_order_id; ?>'
                            style="width: 120px;" rel="<?php echo $customer_order->id; ?>">
                            <option value=0 <?php if ($customer_order->order_status == 0) echo 'selected'; ?>>Store</option>
                            <option value=1 <?php if ($customer_order->order_status == 1) echo 'selected'; ?>>Online
                            </option>
                            <option value=2 <?php if ($customer_order->order_status == 2) echo 'selected'; ?>>Hàng có sẵn
                            </option>
                            <option value=3 <?php if ($customer_order->order_status == 3) echo 'selected'; ?>>Đã nhận hàng
                            </option>
                            <option value=4 <?php if ($customer_order->order_status == 4) echo 'selected'; ?>>Đang
                                shipping
                            </option>
                            <option value=5 <?php if ($customer_order->order_status == 5) echo 'selected'; ?>>Khách đã
                                nhận
                            </option>
                            <option value=6 <?php if ($customer_order->order_status == 6) echo 'selected'; ?>>Hết hàng
                            </option>
                            <option value=7 <?php if ($customer_order->order_status == 7) echo 'selected'; ?>>ORDER</option>
                            <option value=8 <?php if ($customer_order->order_status == 8) echo 'selected'; ?>>Chưa chắc
                                chắn
                            </option>
                        </select>
                        <?php
                        if ($customer_order->order_status == 0) {
                            echo '<div>' . $core->changeDateMysqlToShow($customer_order->store_date) . '</div>';
                        } elseif ($customer_order->order_status == 1) {
                            echo '<div>' . $core->changeDateMysqlToShow($customer_order->online_date) . '</div>';
                        } elseif ($customer_order->order_status == 3) {
                            echo '<div>' . $core->changeDateMysqlToShow($customer_order->received_date) . '</div>';
                        } elseif ($customer_order->order_status == 5) {
                            echo '<div>' . $core->changeDateMysqlToShow($customer_order->saled_date) . '</div>';
                        } elseif ($customer_order->order_status == 7) {
                            echo '<div>' . $core->changeDateMysqlToShow($customer_order->customer_order_date) . '</div>';
                        }
                        ?>
                        <div class="history_status"></div>
                    </td>
                    <td class="center color_status">
                        <p class="description_product_detail" data-item-id="<?php echo $customer_order->id; ?>"><?php echo nl2br(htmlspecialchars($customer_order->description)); ?></p>
                        <button class="popup_edit_note_product" class="btn" type="button" rel="<?php echo $customer_order->id; ?>">Sửa</button>
                    </td>
                    <td class="center gp_3"
                        id="td_price_<?php echo $customer_order->id; ?>"><?php if ($customer_order->order_status == 6) echo '0'; else echo number_format($customer_order->product_price / 1000); ?></td>
                    <td class="center gp_2"
                        id="td_stamp_price_<?php echo $customer_order->id; ?>"><?php if ($customer_order->order_status == 6) echo '0'; else echo number_format($customer_order->stamp_price); ?></td>
                    <td class="center gp_1"
                        id="td_store_price_<?php echo $customer_order->id; ?>"><?php if ($customer_order->order_status == 6) echo '0'; else echo number_format($customer_order->store_price); ?></td>
                </tr>
            <?php
            }
        }
    }
    ?>
    </tbody>
</table>